import AbpBase from './abpbase'
import { Component, Vue,Inject, Prop,Watch } from 'vue-property-decorator';

@Component
export default class ModalBase extends AbpBase{
    @Prop({type:Boolean,default:false}) value:boolean;
    formId:string = 'modal-form' + Date.now;
    async saveFunc():Promise<Boolean>{
        return true;
    }
    save(){
        (this.$refs[this.formId] as any).validate(async (valid:boolean)=>{
            if(valid){
                var success:Boolean = await this.saveFunc();
                if(success){
                    (this.$refs[this.formId] as any).resetFields();
                    this.$emit('save-success');
                    this.$emit('input',false);
                }
            }
        })
    }
    cancel(){
        (this.$refs[this.formId] as any).resetFields();
        this.$emit('input',false);
    }
    visibleChange(value:boolean){
        if(!value){
            this.$emit('input',value);
        }
    }
}